package com.qf.common.core.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Author hehecheng
 * Date 2024/9/4
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel
public class R<T> {

    @ApiModelProperty(value = "返回状态码")
    private Integer code;

    @ApiModelProperty(value = "返回消息")
    private String msg;

    @ApiModelProperty(value = "返回数据")
    private T data;

    public static <T> R<T> ok() {
        return new R<>(200, "成功", null);
    }

    public static <T> R<T> ok(T data) {
        return new R<T>(200, "成功", data);
    }

    public static <T> R<T> ok(String msg, T data) {
        return new R<T>(200, msg, data);
    }

    public static <T> R<T> fail(String msg) {
        return new R<>(500, msg, null);
    }

    public static <T> R<T> fail() {
        return new R<>(500, "失败", null);
    }

    public static <T> R<T> fail(int code, String msg) {
        return new R<>(code, msg, null);
    }
}
